home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Documentation / Tech Notes & Articles / Recipes / Storage / Bento Container Suite < prev    next >
Encoding:
Text File  |  1995-07-11  |  2.9 KB  |  74 lines  |  [TEXT/ttxt]

  1. OpenDocâ„¢ Recipes
  2.  
  3. Bento Container Suite
  4. By The OpenDoc Design Team
  5. July 11, 1995
  6.  
  7.  
  8. © 1993-1995  Apple Computer, Inc. All Rights Reserved.
  9. Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
  10. Mac and OpenDoc are trademarks of Apple Computer, Inc.  (Palatino/10/Plain)
  11.  
  12.  
  13. Changes since DR2:
  14.  
  15. 1) Container ID for File Container must be the size of the used part of the FSSpec.
  16.  
  17. What is Bento Container Suite?
  18.  
  19. A container suite is an implementation of several storage classes (ODContainer, ODDocument, ODDraft and ODStorageUnit) which provides the main functionality of of the OpenDoc storage system. The functionality includes the maintanence of documents, drafts, persistent objects and storage units.
  20.  
  21. The Bento Container Suite is a container suite based on Bento (a.k.a. Container Mangaer) technology. It will be shipped with OpenDoc 1.0.
  22.  
  23. The Bento Container Suite currently supports two kinds of containers: file containers and in-memory containers. File containers are persistent across sessions while in-memory containers are ephemeral.
  24.  
  25. Container
  26.  
  27. How to create a BCS File Container?
  28.  
  29. In OpenDoc, every container is created through the ODStorageSystem. 
  30.  
  31.     ODByteArray ba;
  32.     // Set the length to the size of the file spec which contains meaningful data.
  33.  ba._length = sizeof(short) + sizeof(long) + fsSpec->name[0] + 1;
  34.     ba._maximum = sizeof(FSSpec);
  35.     ba._buffer = fsSpec; // where fsSpec is the FSSpec* of the file to be opened.
  36.  
  37.     ODContainer*    newContainer = session->GetStorageSystem(ev)->
  38.         CreateContainer(ev,kODDefaultFileContainer,&ba);
  39.  
  40. How to create a BCS In-memory Container?
  41.  
  42. In OpenDoc, every container is created through the ODStorageSystem. 
  43.  
  44.     ODByteArray ba;
  45.     ba._length = sizeof(ODHandle);
  46.     ba._maximum = sizeof(ODHandle);
  47.     ba._buffer = &handle;    // where handle is the Handle where the Bento Container is going to live.
  48.  
  49.     ODContainer* newContainer = session->GetStorageSystem(ev)->
  50.         CreateContainer(ev, kODDefaultMemoryContainer, ba);
  51.  
  52. How to get the FSSpec from a BCS File Container?
  53.  
  54. This is not recommended because there is no way to tell whether a container is a BCS File Container or not. However, if you are sure that the container is a BCS file container and you really need to know the FSSpec, here's how you do it.
  55.  
  56.     // Get the container ID.
  57.     ODContainerID containerID = container->GetID(ev);
  58.  
  59.     // The returned container ID contains the FSSpec in _buffer.
  60.     // Note that the returned ID may have _length smaller than sizeof(FSSpec).
  61.     FSSpec* fsSpec = (FSSpec*) containerID->_buffer;
  62.     
  63.     // Use it
  64.     ........
  65.  
  66.     // Dispose the _buffer in the byte array (i.e., the container ID)
  67.     ODDisposePtr(containerID->_buffer);
  68.  
  69. WARNING: Again, this is not recommended!
  70.  
  71.  
  72. Garbage Collection
  73.  
  74. The Bento Container Suite supports garbage collection. It is triggered when a draft is saved. In order to not to lose your persistent objects, you should create references to all the persistent objects you are using during Externalize.